﻿using System;
using TYBase;

namespace DS_2024_02.Data {
    public static class AppIniData {

        static AppIniData() {
            Init();
        }
        public static string LotId { get; set; } = "20241006";
        public static string PreLotId { get; set; } = "";
        public static int StationNo1 { get; set; } = 1;
        public static int StationNo2 { get; set; } = 2;
        public static int CCDDelaySecond { get; set; } = 5;
        public static int CCDWaitOuttime { get; set; } = 20;
        public static int EndChargeWaitOuttime { get; set; } = 20;
        public static int RobotWaitOuttime { get; set; } = 20;
        public static int RobotDelaySecond { get; set; } = 10;
        public static string Dir_PreCharge { get; set; } = "";
        public static string ConnectString { get; set; } = "Server=127.0.0.1;Port=3306;Database=db_battery_check;uid=root;pwd=Aa123456 ;default command timeout=20;";
 

        public static bool IsErrorOnCCD { get; internal set; }
        public static bool IsWarningOnCCD { get; internal set; }
        public static bool IsErrorOnRobot { get; internal set; }
        public static bool IsWarningOnRobot { get; internal set; }
        public static bool IsWarningOnPreCharge { get; internal set; }
        public static bool IsErrorOnPreCharge { get; internal set; }
        public static bool IsErrorOnScan { get; internal set; }
        public static bool IsWarningOnScan { get; internal set; } 
        public static bool IsErrorOnEndCharge { get; internal set; }
        public static bool IsErrorOnEndCharge2 { get; internal set; }
        public static bool IsWarningOnPreCharge2 { get; internal set; }
        public static bool IsErrorOnPreCharge2 { get; internal set; }

        public static string SaveDir = "d:\\eve_data";


        public static void Init() {
            //PLCPort1 = AppData.ini.ReadInt(nameof(PLCPort1), PLCPort1);
            //PLCPort2 = AppData.ini.ReadInt(nameof(PLCPort2), PLCPort2);
            CCDDelaySecond = AppData.ini.ReadInt(nameof(CCDDelaySecond), CCDDelaySecond);
            CCDWaitOuttime = AppData.ini.ReadInt(nameof(CCDWaitOuttime), CCDWaitOuttime);
            RobotWaitOuttime = AppData.ini.ReadInt(nameof(RobotWaitOuttime), RobotWaitOuttime);
            RobotDelaySecond = AppData.ini.ReadInt(nameof(RobotDelaySecond), RobotDelaySecond);
            Dir_PreCharge = AppData.ini.ReadString(nameof(Dir_PreCharge), Dir_PreCharge);

            LotId = AppData.ini.ReadString(nameof(LotId), "");
            PreLotId = AppData.ini.ReadString(nameof(PreLotId), PreLotId);
            SaveDir = AppData.ini.ReadString(nameof(SaveDir), SaveDir);


            //if (LotId.Null()) {
            //    LotId = DateTime.Now.ToString("yyyy_MM_dd");
            //    AppData.ini.WriteString(nameof(LotId), LotId);
            //}
            AppData.ini.WriteInt(nameof(StationNo1), StationNo1);
            AppData.ini.WriteInt(nameof(StationNo2), StationNo2);


            AppIniData.IsErrorOnScan = AppData.ini.ReadBool(nameof(AppIniData.IsErrorOnScan));
            AppIniData.IsWarningOnScan = AppData.ini.ReadBool(nameof(AppIniData.IsWarningOnScan));

            AppIniData.IsErrorOnCCD = AppData.ini.ReadBool(nameof(AppIniData.IsErrorOnCCD));
            AppIniData.IsWarningOnCCD = AppData.ini.ReadBool(nameof(AppIniData.IsWarningOnCCD));

            AppIniData.IsErrorOnRobot = AppData.ini.ReadBool(nameof(AppIniData.IsErrorOnRobot));
            AppIniData.IsWarningOnRobot = AppData.ini.ReadBool(nameof(AppIniData.IsWarningOnRobot));

            AppIniData.IsWarningOnPreCharge = AppData.ini.ReadBool(nameof(AppIniData.IsWarningOnPreCharge));
            AppIniData.IsErrorOnPreCharge = AppData.ini.ReadBool(nameof(AppIniData.IsErrorOnPreCharge));

            AppIniData.IsWarningOnPreCharge2 = AppData.ini.ReadBool(nameof(AppIniData.IsWarningOnPreCharge2));
            AppIniData.IsErrorOnPreCharge2 = AppData.ini.ReadBool(nameof(AppIniData.IsErrorOnPreCharge2));

            AppIniData.IsErrorOnEndCharge = AppData.ini.ReadBool(nameof(AppIniData.IsErrorOnEndCharge));
            AppIniData.IsErrorOnEndCharge2 = AppData.ini.ReadBool(nameof(AppIniData.IsErrorOnEndCharge2));

        }
    }
}
